﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace KimPhongCRM.Lib
{
    public static class SessionData
    {
        public readonly static string Session_Key = HttpContext.Current.Session.SessionID;

        public static string ClientId
        {
            get { return HttpContext.Current.User.Identity.Name != null ? HttpContext.Current.User.Identity.Name : string.Empty; }
            set { HttpContext.Current.Session[Session_Key] = value; }
        }
        /// <summary>
        /// Kiểm tra tồn tại Session
        /// </summary>
        /// <param name="key">Key</param>
        /// <returns>Boolean tồn tại</returns>
        public static bool isSession(string key)
        {
            if (HttpContext.Current.Session[key] == null)
            {
                return false;
            }
            return true;
        }
        public static void StartSession(string key, object value)
        {
            HttpContext.Current.Session[key] = value;
        }

        public static void ListToSession(string key,List<object> list)
        {
            HttpContext.Current.Session[key] = list;
        }

        public static void SessionToList(string key, object list)
        {
            list = (List<object>)HttpContext.Current.Session[key];
        }

        public static void ClearSession()
        {
            HttpContext.Current.Session.Clear();
        }
        public static void RemoveSession(string key)
        {
            HttpContext.Current.Session.Remove(key);
        }
        public static string GetSession(string key) { 
            if(isSession(key))
                return HttpContext.Current.Session[key].ToString();
            return string.Empty;
        }
        public static object GetSessionObject(string key) {
            if (isSession(key))
                return HttpContext.Current.Session[key];
            return null;
        }
    }
}
